package com.xl.utils.service.serviceimpl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xl.utils.entity.TUser;
import com.xl.utils.mapper.TUserMapper;
import com.xl.utils.model.qo.PageQO;
import com.xl.utils.model.vo.UserInfoVO;
import com.xl.utils.service.UserService;
import com.xl.utils.util.StartPageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @Author xionglin
 * @Classname UserServiceImpl
 * @Description TODO
 * @Date 2019/6/12 17:22
 */
@Service
public class UserServiceImpl implements UserService {
    private TUserMapper tUserMapper;


    @Autowired
    public UserServiceImpl(TUserMapper tUserMapper) {
        this.tUserMapper = tUserMapper;
    }

    @Override
    public PageInfo getUser(TUser user){
        Page<Object> page = PageHelper.startPage(1, 1);
        tUserMapper.select(user);
        PageInfo<Object> PageInfo = page.toPageInfo();
        return PageInfo;
    }

    @Override
    public List<UserInfoVO> findUserByUser(TUser user) {
        List<UserInfoVO> userByUser = tUserMapper.findUserByUser(user);
        return userByUser;
    }

    @Override
    public Page getUser(PageQO pageQO, TUser user) {
        Page<Object> page = StartPageUtil.startPage(pageQO);
        tUserMapper.select(user);
        PageHelper.clearPage();
        return page;
    }

    @Override
    public void selectTestPageHelperOrderByFiled() {
        TUser tUser = new TUser();
        tUser.settName("xl");
        PageHelper.startPage(1,1,"t_age desc,t_name desc");
        List<TUser> select = tUserMapper.select(tUser);
        System.out.println("select------->"+select);
    }
}
